package com.ly.honor.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ly.honor.entity.PlayerPlace;
import com.ly.honor.entity.dto.PlayerPlaceCreateDTO;
import com.ly.honor.entity.dto.PlayerPlaceEditDTO;
import com.ly.honor.entity.vo.PlayerPlaceQueryVO;
import com.ly.honor.service.PlayerPlaceService;
import com.ly.honor.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.Serializable;
import java.util.List;

/**
 * (PlayerPlace)表控制层
 *
 * @author makejava
 * @since 2022-11-16 11:53:59
 */
@RestController
@RequestMapping("playerPlace")
@Api(tags = "位置管理")
public class PlayerPlaceController  {
    /**
     * 服务对象
     */
    @Resource
    private PlayerPlaceService playerPlaceService;

    /**
     * 分页查询所有数据
     *
     * @return 所有数据
     */
    @ApiOperation("分页查询所有数据")
    @GetMapping("selectPlayerPlacePage/{pageNum}/{pageSize}")
    public Result selectPlayerPlacePage(@PathVariable("pageNum") long pageNum,
                                        @PathVariable("pageSize") long pageSize) {
        Page<PlayerPlaceQueryVO> playerPlaceQueryVOPage =  playerPlaceService.selectPlayerPlacePage(pageNum,pageSize);
        return Result.ok(playerPlaceQueryVOPage);
    }

    @ApiOperation("通过游戏id查询所有位置信息")
    @PostMapping("selectPlaceAll")
    public Result selectPlaceAll( long gameId){
        return Result.ok(playerPlaceService.selectPlaceAll(gameId));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("通过主键查询单条数据")
    @GetMapping("getPlayerPlaceById/{id}")
    public Result getPlayerPlaceById(@PathVariable long id) {
        PlayerPlaceQueryVO playerPlaceQueryVO = playerPlaceService.getPlayerPlaceById(id);
        return Result.ok(playerPlaceQueryVO);
    }

    /**
     * 新增数据
     *
     * @param playerPlaceCreateDTO 实体对象
     * @return 新增结果
     */
    @ApiOperation("新增选手位置")
    @PostMapping("insertPlayerPlace")
    public Result insertPlayerPlace(@RequestBody @Valid PlayerPlaceCreateDTO playerPlaceCreateDTO) {
        playerPlaceService.insertPlayerPlace(playerPlaceCreateDTO);
        return Result.ok();
    }

    /**
     * 修改数据
     *
     * @param playerPlaceEditDTO 实体对象
     * @return 修改结果
     */
    @ApiOperation("修改选手位置信息")
    @PostMapping("updatePlayerPlace")
    public Result updatePlayerPlace(@RequestBody @Valid PlayerPlaceEditDTO playerPlaceEditDTO) {
        playerPlaceService.updatePlayerPlace(playerPlaceEditDTO);
        return Result.ok();
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除结果
     */
    @ApiOperation("通过id删除信息")
    @DeleteMapping("deletePlayerPlaceById/{id}")
    public Result deletePlayerPlaceById(@PathVariable("id") long id) {
        playerPlaceService.removeById(id);
        return Result.ok();
    }

    /**
     * 批量删除
     * @param idList
     * @return
     */
    @ApiOperation("批量删除")
    @DeleteMapping("removeBatch")
    public Result removeBatch(@RequestBody List<Long> idList) {
        playerPlaceService.removeByIds(idList);
        return Result.ok();
    }
}

